#!/bin/bash
# usage: ./stash_data.sh /path/to/datastore/location "comment describing the experiment"
#
# do this after you have run and analyzed the experiment in a directory so you can go back later and do more work on it
#
# spikes*dat files are tar'd and zip'd to reduce space usage
# moves the spikes, saved simulation state, and model information away to datastore
# also moves figures(fig/pdf/jpg) and analyses (mat)
# includes a description of code versioning info from git so the run could be reproduced, and a comment from the experimentor
#
# for best results in reproducability its a good idea to regularly commit and tag the code so 
# that the DATA_DESCRIPTION diff doesn't get out of hand.

timestamp=$(date "+%Y-%m-%d-%H:%M")
#dataroot=/Volumes/STSTDP-nnrobot-Data
dataroot=$1

datadir=$dataroot/save$timestamp

mkdir $datadir

echo "making data description"
echo $2 > DATA_DESCRIPTION
echo "" >> DATA_DESCRIPTION
git describe --all >> DATA_DESCRIPTION
echo "" >> DATA_DESCRIPTION
git rev-parse HEAD >> DATA_DESCRIPTION
echo "" >> DATA_DESCRIPTION
git diff HEAD >> DATA_DESCRIPTION

echo "zipping up spike history"
find . -maxdepth 1 -name 'spike*.dat' -print | tar -cvzf spikehist.tar.gz --files-from -

echo "deleting spike*.dat"
find . -maxdepth 1 -name 'spike*.dat' -print | xargs rm

echo "copying spike history"
cp spikehist.tar.gz $datadir

echo "copying model and description"
cp *.dat $datadir 
cp DATA_DESCRIPTION $datadir
cp circuits.mat $datadir
cp world.h $datadir

echo "copying dynamics"
cp *.bra $datadir
cp *.neu $datadir
cp *.syn $datadir
cp *.dyn $datadir

echo "copying analysis"
cp *.pdf $datadir
cp *.jpg $datadir
cp *.fig $datadir

# delete after cp instead of mv for safety
echo "deleting everything else, but not the model-making mat/dat files"
rm DATA_DESCRIPTION *.bra *.neu *.syn spikehist.tar.gz *.pdf *.jpg *.fig